<?php session_start();?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
    <head>
        <LINK REL=StyleSheet HREF="maintenancePagesCSS.css" TYPE="text/css" />
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Product Search</title>
    </head>
    <body><center>
    <h3>&nbsp;</h3>
    </center>

<?php
$arrayOValues = -1;
if($_POST['searchBox'] && $_POST['searchCriteria'])
{
    //do the searchinclude "Datasource.php";
    include "ProductDetails.php";
    include "ProductDetailsDao.php";
    include "Datasource.php";

    $connection = new Datasource("localhost","theanykey","root","");
    $productDetailsDao = new ProductDetailsDao();
    $part = new ProductDetails();
    if($_POST['searchCriteria'] == 'Manufacturer')
    {
        $part->setManufacturer($_POST['searchBox']);
    }
    else
    {
        //search by TechNotes
        $part->setTechNotes($_POST['searchBox']);
    }

    $arrayOValues = $productDetailsDao->searchMatching($connection, $part);
}
$_POST['searchBox'] = null;
?>




        <script type='text/javascript' src='tabber.js'></script>
        <link rel='stylesheet' href='triumph.css' TYPE='text/css' MEDIA='screen'>


        <script type='text/javascript'>

            /* Optional: Temporarily hide the 'tabber' class so it does not 'flash'
           on the page as plain HTML. After tabber runs, the class is changed
           to 'tabberlive' and it will appear. */

            document.write('<style type='text/css'>.tabber{display:none;}<\/style>');
        </script>



        <style type="text/css">
            <!--
            .style3 {color: #FFFFFF}
            -->
        </style>
        <center>
            <form method="post" action="productPopup.php" id="ProductSearchForm">
            <div>
            <br>
                <table width="100%" class="SelectTable">
                    <thead>
                        <tr>
                          <th colspan="2" align="center">Product Search </th>
                        </tr>
                    </thead>
                    <tbody>
                        <tr>
                            <td align="center">
                                <input type="text" name="searchBox" value="" size="25" id="searchBox"/>                            </td>
                            <td align="center">
                                <select name ="searchCriteria" id ="searchCriteria">
                                    <option value ="Manufacturer">
                                        Manufacturer                                    </option>
                                    <option value ="TechNotes">
                                        Tech Notes                                    </option>
                                </select>                            </td>
                        </tr>
                    </tbody>
                </table>
                    <br>
                            <input type="button" value="Search" onclick = checkForm(); />
            </form>
            <br>
            <br>
            </div>
            <br>
            <!--Search Results Area-->
            <?php
                if($arrayOValues == -1)
                {
                }
                else if(sizeof($arrayOValues) > 0)
                {
                    //print
                    print("
                        <table class='MenuDiv2'>
                            <tr>
                                <th align='center' style='width:10%'>
                                    
                                </th>
                                <th align='center'>
                                    Product ID
                                </th>
                                <th align='center'>
                                    Manufacturer
                                </th>
                                <th align='center'>
                                    Model Number
                                </th>
                                <th align='center'>
                                    Serial Number
                                </th>
                                <th align='center'>
                                    Our Price (USD)
                                </th>
                                <th align='center'>
                                    Their Price (USD)
                                </th>
                                <th align='center'>
                                    Tech Notes
                                </th>
                            </tr>
                        ");
                  foreach($arrayOValues as $obj)
                  {
                      $productID = $obj->getProductID();
                      $manufact = $obj->getManufacturer();
                      $Model = $obj->getModelNo();
                      $serial = $obj->getSerialNo();
                      $ourPrice = $obj->getCompanyPrice();
                      $theirPrice = $obj->getCustomerPrice();
                      $techNotes = $obj->getTechNotes();

                      print("
                            <tr>
                                <td align='center'>
                                    <a href='productPopupSearchFunc.php?id=$productID'>Add</a>&nbsp;
                                </td>
                                <td align='center'>$productID</td>
                                <td align='center'>$manufact</td>
                                <td align='center'>$Model</td>
                                <td align='center'>$serial</td>
                                <td align='center'>$ourPrice</td>
                                <td align='center'>$theirPrice</td>
                                <td align='center'>$techNotes</td>
                            </tr>
                            ");
                        $counter++;
                  }//end foreach
                        print("</table></br/>");
                }//end else if
                else
                {

                    //error
                    print("
                           <font style='color: red; font-weight: bold'>
                               Search returned no values.
                           </font>
                            ");
                }
            ?>
            
        </center>
    </body>
    <script type="text/javascript">
        function checkForm()
        {
            if((document.getElementById("searchBox").value == ""))
            {
                alert("Search field is blank.");
            }
            else
            {
                document.getElementById("ProductSearchForm").submit();
            }
        }
        
    </script>
</html>
